pub type Point = (usize, usize);

type Rect = (usize, usize, usize, usize);

pub trait Island {
    fn get_rect(&self) -> Rect;
    fn get_matrix(&self) -> Vec<Vec<bool>>;
}

impl Island for Vec<Point> {
    fn get_rect(&self) -> Rect {
        let (mut left, mut top, mut right, mut bottom): Rect = (usize::MAX, usize::MAX, 0, 0);

        for (x, y) in self {
            if *x > right {
                right = *x;
            }
            if *x < left {
                left = *x;
            }
            if *y > bottom {
                bottom = *y
            }
            if *y < top {
                top = *y
            }
        }

        return (left, top, right, bottom);
    }

    fn get_matrix(&self) -> Vec<Vec<bool>> {
        let rect = self.get_rect();
        let (left, top, right, bottom) = rect;
        let w = right - left + 1;
        let h = bottom - top + 1;
        let mut data = vec![vec![false; w]; h];

        for (x, y) in self {
            data[*y - top][*x - left] = true
        }

        return data;
    }
}
